Easy
Given a list of strings words
representing an English Dictionary, find the longest word in words
that can be built one character at a time by other words in words
. If there is more than one possible answer, return the longest word with the smallest lexicographical order.
If there is no answer, return the empty string.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Note:
All the strings in the input will only contain lowercase letters.
The length of words
will be in the range [1, 1000]
.
The length of words[i]
will be in the range [1, 30]
.
always start from brute force:
可以使用set来加速查找的时间。然后预先排好序(长度从大到小,字典顺序)找到的第一个符合条件的一定就是最优解
1 | class Solution: |